(function($, doc) {
	mui.init({});
	var userinfo = app.getState() || {};
    var uid = userinfo.user_id;

		mui.plusReady(function(){
			var selected_country=plus.webview.currentWebview().selected_country;
			var type =plus.webview.currentWebview().type;
            doc.getElementById('now_country').innerHTML=selected_country;
			mui.ajax({
				url: apiurl + "Trade/state_list/",
				data: {'_token':userinfo.token},
				async: true,
				dataType: 'json',
				crossDomain: true, //强制使用5+跨域
				type: 'get',
				timeout: 10000,
				success: function(res) {
					console.log(JSON.stringify(res));
					if(res.status ==-3){
						mui.alert(res.msg);
						app.out();
						return false;
					}
					// 请求成功
					doc.querySelector("#main-data").innerHTML = template('main-template',
						{ 'state':res.data.state,
						  'sels':selected_country
					});

				},
				error: function(xhr, type, errorThrown) {
					//console.log(JSON.stringify(xhr));
					//console.log(JSON.stringify(type));
					//console.log(JSON.stringify(errorThrown));
					mui.toast('获取数据失败！');
				}
			});
			
			
			mui("#main-data").on('change','.mui-btn.mui-btn-block',function(){
				var s=document.querySelector('#main-data .mui-btn.mui-btn-block').value;
				if(type==1){
					mui.fire(plus.webview.getWebviewById('buy_in.html'),'change_state',{'selcountry':s});
	 				mui.back();
				}
				
				if(type==2){
					mui.fire(plus.webview.getWebviewById('sell_out.html'),'change_state',{'selcountry':s});
	 				mui.back();
				}
				
				if(type==3){
					mui.fire(plus.webview.getWebviewById('buy_center.html'),'change_state',{'selcountry':s});
	 				mui.back();
				}
				
				if(type==4){
					mui.fire(plus.webview.getWebviewById('sell_center.html'),'change_state',{'selcountry':s});
	 				mui.back();
				}
				
			}) 

		});

   

}(mui, document));


/*
function set_state(){
	var s=document.querySelector('#main-data .mui-btn.mui-btn-block').value;
	 mui.fire(plus.webview.getWebviewById('transaction.html'),'change_state',{'selcountry':s});
	 mui.back();
}
*/


